
# 获取百度首页源代码

# 目标 target
target_url = 'http://www.baidu.com'

import urllib.request
# 模拟 浏览器 向服务器发送请求
response = urllib.request.urlopen(target_url)

content = response.read()
# print(content)
# b'<!DOCTYPE html><!--STATUS OK--><html><head><m...

# 将二进制转成字符串   【解码】
content_decode = content.decode('utf-8')
print(content_decode)
# <!DOCTYPE html><!--STATUS OK--><html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta content="always" name="referrer"><meta name="theme-color" content="#ffffff"><meta name="description" content="全球领先的中文搜索引擎、致力于让网民更便捷地获取信息，找到所求。百度超过千亿的中文网页数据库，可以瞬间找到相关的搜索结果。"><link rel="shortcut icon" href="https://www.baidu.com/favicon.ico" type="image/x-icon" /><link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" /><link rel="stylesheet" data-for="result" href="https://pss.bdstatic



